package com.itheima.pattern.decorator

/**
 * @version v1.0
 * @ClassName: Garnish
 * @Description: 装饰者类(抽象装饰者角色)
 * @Author: 黑马程序员
 */
internal abstract class Garnish(//声明快餐类的变量
    var fastFood: FastFood, price: Float, desc: String?
) : FastFood(price, desc)

internal class FriedRice : FastFood(10f, "炒饭") {
    override fun cost(): Float {
        return price
    }
}

internal class FriedNoodles : FastFood(12f, "炒面") {
    override fun cost(): Float {
        return price
    }
}

internal class Bacon(fastFood: FastFood) : Garnish(fastFood, 2f, "培根") {
    override fun cost(): Float {
        //计算价格
        return price + fastFood.cost()
    }

    override var desc: String?
        get() = super.desc + fastFood.desc
        set(desc) {
            super.desc = desc
        }
}

internal class Egg(fastFood: FastFood) : Garnish(fastFood, 1f, "鸡蛋") {
    override fun cost(): Float {
        //计算价格
        return price + fastFood.cost()
    }

    override var desc: String?
        get() = super.desc + fastFood.desc
        set(desc) {
            super.desc = desc
        }
}